<?php

/** 
 * @property Presrent_mdl $presrent
 * 
 */
class Presrent extends Admin_Controller {
	
	/**
	 */
	public function __construct() {
		parent::__construct ();
		$this->load->model('Presrent_mdl','presrent');
		$this->load->model('School_mdl','school');
	}
	
	public function index(){

		$this->load->library('Search_tpl',NULL,'searchTpl');
		$where = array();
		$like  = array();
		$order = 'id';
		$sort  = 'DESC';
		$orders = array(
				'id'=>'id',
				'uid'=>'userID',
				'aid'=>'adminID',
				'time'=>'time',
		);
		$input = $this->input->get(NULL,TRUE);
		foreach ($input as $k=>$v){
			if ($v===''){
				continue;
			}
			$v = trim($v);
			switch ($k) {
				case 'uid':
					$where['userID'] = (int)$v;
					break;
				case 'id':
					$where['id'] = (int)$v;
					break;
				case 'aid':
					$where['adminID'] = (int)$v;
					break;
				case 'adminName':
					$like['adminName'] = $v;
					break;
				case 'nickname':
					$like['userName'] = $v;
					break;
				case 'order' :
					$order = isset($orders[$v]) ? $orders[$v] : 'id';
					break;
				case 'sort':
					$sort = (int)$v===0 ? 'DESC' : 'ASC';
					break;
				case 'phone':
					$where['phone'] = (float)$v;
					break;
				case 'st':
					$where['time >='] = strtotime($v);
					break;
				case 'et':
					$where['time <='] = strtotime($v);
					break;
			}
		}
		$query = array();
		$query['select']= '*';
		$query['from']  = 'hs_presrent_view';
		$query['where'] = $where;
		$query['like']  = $like;
		$query['order'] = $order;
		$query['sort']  = $sort;
		$this->searchTpl->query($query);
		$temp = array();
		$temp['formItems'] = array(
				'uid',
				'nickname',
				array('type'=>'text','label'=>'管理员ID','name'=>'aid'),
				array('type'=>'text','label'=>'管理员','name'=>'adminName'),
				'br',
				array('type'=>'dateRange','label'=>'赠送时间','name'=>array('st','et')),
		);
		$temp ['thList'] = array (
				'id',
				array('text'=>'管理员ID','order'=>'aid'),
				'管理员',
				array('text'=>'用户ID','order'=>'uid'),
				'用户昵称',
				'赠送金额',
				'赠送理由',
				array('text'=>'赠送时间','order'=>'id'),
		);
		$callback = function($v){
			return array(
					$v['id'],
					$v['adminID'],
					$v['adminID']==0 ? '系统自动赠送' : $v['adminName'],
					$v['userID'],
					$v['userName'],
					array('val'=>$v['amount']/100,'class'=>'amount'),
					$v['reason'],
					date('Y-m-d H:i:s',$v['time']),
					
			);
		};
		$temp['tableTitle'] = '赠送纪录列表----共查到%s条记录----';
		$temp['header'] = $this->getViewHeaderData();
// 		$temp['jsCtrl'] = 'userCtrl';
		$this->searchTpl->show($temp,$callback);
		
	}
	
	
}

